const express = require('express');
const router = express.Router();
const merchantController = require('../controllers/merchantController');
const { protect } = require('../middleware/authMiddleware');
const fileUpload = require('express-fileupload');

// 配置文件上传中间件
router.use(fileUpload({
    limits: { fileSize: 5 * 1024 * 1024 }, // 限制5MB
    abortOnLimit: true,
    createParentPath: true,
    useTempFiles: true,
    tempFileDir: '/tmp/'
}));

// 认证相关路由
router.post('/login', merchantController.login);
router.post('/send-code', merchantController.sendCode);

// 商户概览数据
router.get('/overview', protect, merchantController.getOverview);

// 店铺信息管理
router.get('/store-info', protect, merchantController.getStoreInfo);
router.put('/store-info', protect, merchantController.updateStoreInfo);
router.post('/upload-logo', protect, merchantController.uploadLogo);

// 订单管理
router.get('/orders', protect, merchantController.getOrders);
router.get('/orders/:id', protect, merchantController.getOrderDetail);
router.put('/orders/:id/status', protect, merchantController.updateOrderStatus);

// 优惠券管理
router.get('/coupons', protect, merchantController.getCoupons);
router.post('/coupons', protect, merchantController.createCoupon);
router.put('/coupons/:id/disable', protect, merchantController.disableCoupon);

module.exports = router; 